<template>
    <div>
        <el-form label-width="80px" :inline="true">
            <template v-for="(item) in searchFormObject">
                <el-form-item :label="item.label" v-if="item.type=='select' && searchOptions[item.field]!=true">
                    <el-select
                            v-model="searchForm[item.field]"
                            :placeholder="'请选择'+item.label"
                            @change="handleSearchChange"
                            size="small"
                            clearable
                            filterable
                    >
                        <el-option v-for="data in item.options"
                                   :key="data.id"
                                   :label="data.name"
                                   :value="data.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="item.label" v-else-if="item.type == 'input' && searchOptions[item.field]!=true">
                    <el-input
                            v-model="searchForm[item.field]"
                            :placeholder="'请输入'+item.label"
                            size="small"
                            clearable
                    />
                </el-form-item>
                <el-form-item :label="item.label" v-else-if="item.type == 'datetime' && searchOptions[item.field]!=true">
                    <el-date-picker
                            clearable
                            format="yyyy-MM-dd HH:mm:ss"
                            :value-format="'yyyy-MM-dd HH:mm:ss'"
                            v-model="searchForm[item.field]"
                            type="datetimerange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            size="small"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item :label="item.label" v-else-if="item.type == 'date' && searchOptions[item.field]!=true">
                    <el-date-picker
                            clearable
                            format="yyyy-MM-dd"
                            :value-format="'yyyy-MM-dd'"
                            v-model="searchForm[item.field]"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            size="small"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item :label="item.label" v-else-if="item.type == 'monthrange' && searchOptions[item.field]!=true">
                    <el-date-picker
                            clearable
                            format="yyyy-MM"
                            :value-format="'yyyy-MM'"
                            v-model="searchForm[item.field]"
                            type="monthrange"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始月份"
                            end-placeholder="结束月份"
                            size="small">
                    </el-date-picker>
                </el-form-item>
            </template>

            <el-form-item label=" ">
                <el-button size="mini" @click="handleSearch()" icon="el-icon-search" type="primary">查询</el-button>
                <el-button size="mini" @click="handleReset()">重置</el-button>
                <el-button size="mini" @click="handleExport()" type="primary" v-if="exportOptions">导出</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        props: ['searchOptions', 'searchForm', 'searchFormObject','exportOptions'],
        components: {},
        data() {
            return {}
        },
        created() {
        },
        methods: {
            //父页面的回调事件
            handleSearchChange() {
                this.$emit('changeSearchForm', this.searchForm)
            },
            //父页面的回调事件
            handleParentEvent() {
                this.$emit('setSearchForm', this.searchForm)
            },
            //父页面的回调事件
            handleExport() {
                this.$emit('setExport', this.searchForm)
            },
            //创建
            handleSearch() {
                this.handleParentEvent()
            },
            handleReset() {
                for (let k in this.searchForm) {
                    this.searchForm[k] = "";
                }
                this.handleParentEvent()
            },
        }
    }
</script>

<style scoped>

</style>
